package zh.javadesign.工厂方法.impl02.store;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zh.javadesign.工厂方法.Scene.goods.DeliverReq;
import zh.javadesign.工厂方法.Scene.goods.GoodsService;

import java.util.Map;

/**
 * Copyright (C) 广州中和互联网技术有限公司
 *
 * @author 范家微 fanjiawei@borche.cn
 * @date :2021/1/29 11:46
 */
public class GoodsCommodityService implements ICommondity {
	private Logger logger = LoggerFactory.getLogger(GoodsCommodityService.class);

	@Override
	public void sentCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) {
		GoodsService goodsService = new GoodsService();
		Boolean isSuccess = goodsService.deliverGoods(new DeliverReq().setUserName(queryUserName(uId))
				.setUserPhone(queryUserPhoneNumber(uId))
				.setOrderId(bizId).setSku(commodityId)
				.setConsifneeUserPhone(extMap.get("consigneeUserName"))
				.setConsifneeUserPhone(extMap.get("consigneeUserPhone"))
				.setConsigneeUserAddress(extMap.get("consigneeUserAddress")));
		logger.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", uId, commodityId, bizId, JSON.toJSON(extMap));
		logger.info("测试结果[优惠券]：{}", isSuccess);
		if (!isSuccess) throw new RuntimeException("实物商品发放失败");
	}

	private String queryUserName(String uId) {
		return "花花";
	}

	private String queryUserPhoneNumber(String uId) {
		return "15200101232";
	}
}
